package com.xuxueli.commontdemo.commont;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 存储db类型
 */
public class DataSourceContextHolders {
    public static final ThreadLocal<String> contextHolder=new ThreadLocal<>();
    private static final Logger logger = LoggerFactory.getLogger(DataSourceContextHolders.class);

    // 设置数据源名
    public static void setDB(String dbType) {
        contextHolder.set(dbType);
        logger.info("数据源名字:"+dbType);
    }

    // 获取数据源名
    public static String getDB() {
        if (contextHolder.get() == null) {
            return "masterDataSource";
        }
        return (contextHolder.get());
    }

    // 清除数据源名
    public static void clearDB() {
        contextHolder.remove();
    }
}